package com.tzvtc.server.students.controller;


import cn.hutool.http.server.HttpServerRequest;
import com.github.pagehelper.PageInfo;
import com.tzvtc.server.commons.bean.PageRequestBean;
import com.tzvtc.server.commons.bean.ResultBean;
import com.tzvtc.server.students.bean.StudentBean;
import com.tzvtc.server.students.service.StudentService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//直接返回页面
//@Controller

//@RestController将方法返回的内容格式化成json字符串
@Slf4j
@RestController
@RequestMapping("student")
public class StudentController {


    private final StudentService studentService;

    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }


    //服务端返回给客户端状态码、描述信息、数据
    @RequestMapping("list")
    public ResultBean list(@RequestBody PageRequestBean<StudentBean> pageRequestBean) {
        log.info("/student/list, 用户查询参数: {}",pageRequestBean);
        PageInfo<StudentBean> pageInfo = studentService.list(pageRequestBean);
        log.info("/student/list, 用户列表，查询结果: {}", pageInfo);
        return ResultBean.success(pageInfo);
    }


    @RequestMapping("remove")
    public ResultBean delete(@RequestBody StudentBean studentBean) {
        studentService.remove(studentBean);
        return ResultBean.success("删除成功");
    }


    @RequestMapping("save")
    public ResultBean insert(@RequestBody StudentBean studentBean) {
        studentService.insert(studentBean);
        return ResultBean.success("保存成功");
    }

    @RequestMapping("info")
    public ResultBean info(@RequestBody StudentBean studentBean){
        log.info("student/info,学生信息详情, 接收参数:{}",studentBean);
        StudentBean resultBean = studentService.info(studentBean);
        log.info("student/info,学生信息详情, 结果:{}",resultBean);
        return ResultBean.success(resultBean);
    }
}
